pub struct Solution;

impl Solution {
    pub fn process_queries(queries: Vec<i32>, m: i32) -> Vec<i32> {
        let mut vec: Vec<i32> = (1..=m).collect();

        queries.into_iter().map(move |i| {
            let pos = vec.iter().position(|j| *j == i).unwrap();
            vec.remove(pos);
            vec.insert(0, i);
            pos as i32
        }).collect::<Vec<i32>>()
    }
}

fn main() {
    Solution::process_queries(vec![1, 2, 3], 3);
}

#[cfg(test)]
mod test {
    use crate::Solution;

    #[test]
    fn test_01() {
        let res = Solution::process_queries(vec![3, 1, 2, 1], 5);
        assert_eq!(res, vec![2, 1, 2, 1]);
    }

    #[test]
    fn test_02() {
        let res = Solution::process_queries(vec![4,1,2,2], 4);
        assert_eq!(res, vec![3,1,2,0]);
    }

    #[test]
    fn test_03() {
        let res = Solution::process_queries(vec![7,5,5,8,3], 8);
        assert_eq!(res, vec![6,5,0,7,5]);
    }
}
